<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>01-刷底色</title>
  <link rel="icon" href="https://img.kaikeba.com/kkb_portal_icon.ico">
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }

    #canvas {
      background-color: antiquewhite;
    }
  </style>
</head>

<body>
  <canvas id="canvas"></canvas>
  <script>
    const canvas = document.querySelector("#canvas");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    //二维画笔
    // const gl=canvas.getContext('2d');
    //三维画笔
    const gl = canvas.getContext("webgl");
    //声明颜色 rgba
    gl.clearColor(1, 1, 0, 1);
    //刷底色
    gl.clear(gl.COLOR_BUFFER_BIT);

    //css颜色
    const rgbaCss = "rgba(255,100,0,1)";
    //正则
    const reg = RegExp(/\((.*)\)/);
    //捕捉数据
    const rgbaStr = reg.exec(rgbaCss)[1];
    console.log(rgbaStr);
    //加工数据
    const rgba = rgbaStr.split(",").map((n) => parseInt(n));
    console.log(rgba);

    const r = rgba[0] / 255;
    const g = rgba[1] / 255;
    const b = rgba[2] / 255;
    const a = rgba[3];
    //声明颜色 rgba
    gl.clearColor(r, g, b, a);
    //刷底色
    gl.clear(gl.COLOR_BUFFER_BIT);
  </script>
</body>

</html>